import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *

testcase = "DBshop011_商品管理管理商品添加商品"

firefox = openBrowser(urlAdmin)
DBshopLoginAdmin(firefox)

# 1.点击添加商品按钮，
firefox.find_element_by_xpath('//i[@class="icon-plus icon-white"]').click()
# firefox.find_element_by_xpath('//a[@class="btn btn-primary"]')[6].click()
s1 = firefox.find_element_by_xpath("//body").text
l1 = '商品数：'
r1 = '\)'
num1 = reGetString(s1,l1,r1)
# s=firefox.find_element_by_xpath("//body").text
# print(s)
# l="商品数\："
# r="\)"
# num1=reGetString(s,l,r)
print(num1)

firefox.find_element_by_xpath('//a[@class="btn btn-small btn-primary"]').click()
# 商品名称填写“苹果XR”
firefox.find_element_by_id('goods_name').send_keys("苹果XR")
# 本店价格“7999”
firefox.find_element_by_id("goods_shop_price").send_keys("7999")
# 商品类型“虚拟商品”。
firefox.find_element_by_id("goods_type").click()
firefox.find_element_by_xpath('//option[@value="2"]').click()

# 2.点击“保存商品”按钮，后台保存成功添加的商品。
firefox.find_element_by_xpath('//button[@class="btn btn-small btn-primary"]').click()
time.sleep(5)

# 断言 比较前后商品数量
s = firefox.find_element_by_xpath("//body").text
l = "商品数："
r = "\)"
num2 = reGetString(s,l,r)
print(num2)


if int(num1) +1 == int(num2):
    writeLog("%s 测试通过"%testcase)
else:
    writeLog("%s 测试失败" % testcase)
    getPhoto(firefox)
# firefox.quit()

